package com.ynding.cloud.auth.api.admin.common.util;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ynding.cloud.common.model.util.BeanDtoVoUtils;

import java.util.List;

/**
 * <p> 类转化器 </p>
 *
 * @author ynding
 * @version 2021/11/8
 **/
public class BeanConvertUtils {

    /**
     * 分页转换,简化版
     *
     * @return
     */
    public static <D, T> IPage<D> toPageDO(IPage<T> source, Class<D> dClass) {
        if (source != null) {
            IPage<D> dest = new Page<>(source.getCurrent(), source.getSize(), source.getTotal());
            if (CollectionUtil.isNotEmpty(source.getRecords())) {
                List<T> list = source.getRecords();
                List<D> ds = BeanDtoVoUtils.toDtoList(list, dClass);
                dest.setRecords(ds);
            }
            return dest;
        }
        return null;
    }
}
